﻿using EasyTest.Shared.EnumType;
using EasyTest.Shared.Extensions;
using EasyTest.Shared.TestAttribute;
using EasyTest.Shared.外部访问;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ZLGCANoptimize
{
    /***************************************************************************
    version:1.0
    创建人:xianle
    创建时间:2025/2/17 16:24:38
    *描述：
    *修 改 人：  
    *修改时间：  
    *修改描述：
   *=====================================================================*/
    public class 生产数据
    {
        [ExposedMethodAttribute("")]
        public bool 写入工位SN_F18C(int 工位,int 通道,  out string 信息, out string 写入信息)
        {
            写入信息 = "";
            string sn = 测试模块.获取在测SN(工位-1);
            List<string> list = new List<string>()
            {
                "30", "30", "30", "30", "30", "30", "30", "30",
                "30", "30","30","30","30","30","30","30","30",
            };
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "61");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }

                list.InsertRange(0, sn.ToHexArray());//10 13 2E F1 8C 20 32  33 
                string str1 = $"10 13 2E F1 8C 20 " + String.Join(" ", list.GetRange(0, 2)).Trim();
                string str2 = $"21 " + String.Join(" ", list.GetRange(2, 7)).Trim();
                string str3 = $"22 " + String.Join(" ", list.GetRange(9, 6)).Trim() + " AA";
                写入信息 = str1 + "\r\n" + str2 + "\r\n" + str3;
                //bool result1, result2, result3, result4;
                bool result1, result2, result3, result4;
                result1 = zLGCANHelper.SentData(通道, 0x761, str1, true, SendType.正常发送);
                eLog.AddLog($"写入SN_F18C发送：{str1}", eMsgType.Debug);
                Thread.Sleep(50);
                result2 = zLGCANHelper.SentData(通道, 0x761, "30 00 00 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                result3 = zLGCANHelper.SentData(通道, 0x761, str2, true, SendType.正常发送);
                eLog.AddLog($"写入SN_F18C发送：{str2}", eMsgType.Debug);
                Thread.Sleep(50);
                result4 = zLGCANHelper.SentData(通道, 0x761, str3, true, SendType.正常发送);
                eLog.AddLog($"写入SN_F18C发送：{str3}", eMsgType.Debug);
                Thread.Sleep(50);
                string 返回 = "";
                for (int i = 0; i < 3; i++)
                {
                    Thread.Sleep(50);
                    List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1);
                    string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                    返回 = string.Join(" ", datas);
                    if (返回.Contains("03 6E"))
                    {
                        信息 = "写入SN数据成功";
                        return true;
                    }
                    Thread.Sleep(50);
                }
                eLog.AddLog($"写入SN_F18C响应：{返回}", eMsgType.Debug);
                信息 = "写入SN数据失败:" + 返回;
            }
            catch (Exception ex)
            {
                信息 = "写入SN失败:" + ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 读取SN_F18C(int 通道, out string SN, out int SN字节, out string 信息)
        {

            信息 = "";
            SN = "";
            SN字节 = SN.Length;
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = new List<ZCAN_Receive_Data>();
                SN = CanFactory.GetSN(通道, zLGCANHelper, zCAN_Receive_Datas, out 信息).Trim();
                if (SN == null)
                    return false;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                SN = "";
                return false;
            }
            SN字节 = SN.Trim().Length;
            return true;
        }
        [ExposedMethodAttribute("")]
        public bool 写入SN_F18C(int 通道, string sn, out string 信息,out string 写入信息)
        {
            写入信息 = "";
#if ELO20240927
            List<string> list = new List<string>()
            {
                "30", "30", "30", "30", "30", "30", "30", "30",
                "30", "30","30","30","30","30","30","30","30",
            };
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息,"61");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
        
                list.InsertRange(0, sn.ToHexArray());//10 13 2E F1 8C 20 32  33 
                string str1 = $"10 13 2E F1 8C 20 " + String.Join(" ", list.GetRange(0, 2)).Trim();
                string str2 = $"21 " + String.Join(" ", list.GetRange(2, 7)).Trim();
                string str3 = $"22 " + String.Join(" ", list.GetRange(9, 6)).Trim() + " AA";
                写入信息=str1+ "\r\n" + str2 + "\r\n" + str3;
                //bool result1, result2, result3, result4;
                bool result1, result2, result3, result4;
                result1 = zLGCANHelper.SentData(通道, 0x761, str1, true, SendType.正常发送);
                Thread.Sleep(50);
                result2 = zLGCANHelper.SentData(通道, 0x761, "30 00 00 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                result3 = zLGCANHelper.SentData(通道, 0x761, str2, true, SendType.正常发送);
                Thread.Sleep(50);
                result4 = zLGCANHelper.SentData(通道, 0x761, str3, true, SendType.正常发送);
                Thread.Sleep(50);
                string 返回 = "";
                for (int i = 0; i < 3; i++)
                {
                    Thread.Sleep(50);
                    List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1);
                    string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                    返回 = string.Join(" ", datas);
                    if (返回.Contains("03 6E"))
                    {
                        信息 = "写入SN数据成功";
                        return true;
                    }
                    Thread.Sleep(50);
                }

                信息 = "写入SN数据失败:" + 返回;
            }
            catch (Exception ex)
            {
                信息 = "写入SN失败:" + ex.Message;
            }
            return false;
#else
            List<string> list = new List<string>()

                { "30", "30", "30", "30", "30", "30", "30", "30", "30",
                    "30" ,"30","30","30","30","30","30","30"};
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息);
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                list.InsertRange(0, sn.ToHexArray());//10 13 2E F1 8C 20 32  33 
                string str1 = $"10 13 2E F1 8C 20 " + String.Join(" ", list.GetRange(0, 2)).Trim();
                string str2 = $"21 " + String.Join(" ", list.GetRange(2, 7)).Trim();
                string str3 = $"22 " + String.Join(" ", list.GetRange(9, 6)).Trim() + " AA";

                bool result1, result2, result3, result4;
                result1 = zLGCANHelper.SentData(通道, 0x761, str1, true, SendType.正常发送);
                Thread.Sleep(50);
                result2 = zLGCANHelper.SentData(通道, 0x761, "30 00 00 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                result3 = zLGCANHelper.SentData(通道, 0x761, str2, true, SendType.正常发送);
                Thread.Sleep(50);
                result4 = zLGCANHelper.SentData(通道, 0x761, str3, true, SendType.正常发送);
                Thread.Sleep(50);
                string 返回 = "";
                for (int i = 0; i < 3; i++)
                {
                    List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 1);
                    string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                    返回 = string.Join(" ", datas);
                    if (返回.Contains("03 6E"))
                    {
                        信息 = "写入SN数据成功";
                        return true;
                    }
                    Thread.Sleep(50);
                }


                信息 = "写入SN数据失败:" + 返回;
                return false;
            }
            catch (Exception ex)
            {
                信息 = "写入SN失败:" + ex.Message;
                return false;
            }
#endif
        }
        [ExposedMethodAttribute("")]
        public bool 读ECU生产日期F18B(int 通道,out bool 合法日期 , out string 生产日期, out string 信息)
        {
            生产日期 = "";
            合法日期=false;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";// "06 2E F1 8B 24 07 26 00";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                zLGCANHelper.SentData(通道, 0x761, "03 22 F1 8B 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(80);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);

                zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                Thread.Sleep(50);
                string[] hexValues = new string[5];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("06"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 4 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }

                信息 = string.Join(",", datas);
                生产日期 = String.Join("", hexValues.ToList().GetRange(0, 3)).Trim();

                //判断是否为日期
                合法日期 = IsValidYYMMDD(生产日期);
                //return isValid;

                //修改判断，只要是积极反馈即可,2024-11-07
                var ss = string.Join("", datas).Replace(" ", "");
                if (ss.Contains("62F18B"))
                {
                    return true;  //积极反馈
                }

                return false;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                //LogHelper.Error($"[ZLGCANoptimize.读取生产日期]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[读取生产日期]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        //[ExposedMethodAttribute("")]
        //public bool 写入生产日期F18B(int 通道, out string 响应, out string 命令, out string 信息)
        //{
        //    信息 = "";
        //    响应 = "";
        //    命令 = $"06 2E F1 8B {DateTime.UtcNow.ToString("yy")} {DateTime.UtcNow.ToString("MM")} {DateTime.UtcNow.ToString("dd")} AA";
        //    //  命令 = "06 2E F1 8B 24 07 26 00";
        //    try
        //    {
        //        if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
        //        {
        //            信息 = "启动can设备失败";
        //            return false;
        //        }
        //        _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
        //        bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
        //        if (!OK)
        //        {
        //            //  信息 = "解密失败";
        //            return false;
        //        }
        //        bool result1, result2;
        //        result1 = zLGCANHelper.SentData(通道, 0x761, 命令, true, SendType.正常发送);

        //        if (!result1)
        //        {
        //            信息 = "发送数据失败,写入生产日期失败";
        //            return false;
        //        }
        //        List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
        //        string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);//03 6E 4C 83 AA AA AA AA 
        //        响应 = string.Join("\n", datas);
        //        if (datas.Length > 0)
        //        {
        //            foreach (string s in datas)
        //            {
        //                if (s.Trim().StartsWith("03 6E F1 8B"))
        //                {
        //                    信息 = "写入生产日期成功";
        //                    return true;
        //                }
        //            }
        //        }
        //        //3、关闭
        //        信息 = "写入生产日期失败";
        //        return false;

        //    }
        //    catch (Exception ex)
        //    {
        //        信息 = ex.Message;
        //        throw;
        //    }
        //    return true;
        //}
        [ExposedMethodAttribute("")]
        public bool 读取物流标定数据C00C(int 通道, out string 标定数据C00C, out string 信息)
        {
            标定数据C00C = "";

            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }

                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false, r2 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 0C 00 00 00 00", true, SendType.正常发送);
                    Thread.Sleep(50);
                    r2 = zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1 && r2)
                    {
                        break;
                    }
                }
                if (!r1 || !r2)
                {
                    信息 = "发送失败...";
                    标定数据C00C = 信息;
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);

                string[] hexValues = new string[5];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                foreach (string s in datas)
                {
                    ok10 = true;
                    for (int i = 0; i < s.Split(' ').Length; i++)
                    {
                        if (i < 4 || i > 7) continue;
                        hexValues[num] = s.Split(' ')[i];
                        num++;
                    }
                }

                信息 = string.Join(",", datas);
                标定数据C00C = String.Join("", hexValues);
                return ok10;

            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
            return true;
        }
        [ExposedMethodAttribute("")]
        public bool 写ECU生产日期F18B(int 通道, out string 响应, out string 命令, out string 信息)
        {
            信息 = "";
            响应 = "";
            命令 = $"06 2E F1 8B {DateTime.UtcNow.ToString("yy")} {DateTime.UtcNow.ToString("MM")} {DateTime.UtcNow.ToString("dd")} AA";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                result1 = zLGCANHelper.SentData(通道, 0x761, 命令, true, SendType.正常发送);

                if (!result1)
                {
                    信息 = "发送数据失败,写入生产日期失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E F1 8B"))
                        {
                            信息 = "写入生产日期成功";
                            return true;
                        }
                    }
                }

                信息 = "写入生产日期失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 写配置可追溯字段F198(int 通道, out string 响应, out string 命令, out string 信息)
        {
            信息 = "";
            响应 = "";
            命令 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1, result2, result3;
                /*
                    10 0E 2E F1 98 31 33 33
                    21 33 33 33 33 33 33 33
                    22 39 00 00 00 00 00 00 
                */
                result1 = zLGCANHelper.SentData(通道, 0x761, "10 0E 2E F1 98 31 33 33", true, SendType.正常发送);
                result2 = zLGCANHelper.SentData(通道, 0x761, "21 33 33 33 33 33 33 33", true, SendType.正常发送);
                result3 = zLGCANHelper.SentData(通道, 0x761, "22 39 00 00 00 00 00 00", true, SendType.正常发送);

                if (!result1 || !result2 || !result3)
                {
                    信息 = "发送数据失败,写入配置可追溯字段失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E F1 98"))
                        {
                            信息 = "写入配置可追溯字段成功";
                            return true;
                        }
                    }
                }

                信息 = "写入配置可追溯字段失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 写车辆功能信息F1A8(int 通道, out string 响应, out string 信息)
        {
            信息 = "";
            响应 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                /*
                    10 17 2E F1 A8 FF FF FF
                    21 FF FF FF FF FF FF FF
                    22 FF FF FF FF FF FF FF
                    23 FF FF F1 00 00 00 00 
                 */
                bool result1, result2, result3, result4;
                result1 = zLGCANHelper.SentData(通道, 0x761, "10 17 2E F1 A8 FF FF FF", true, SendType.正常发送);
                result2 = zLGCANHelper.SentData(通道, 0x761, "21 FF FF FF FF FF FF FF", true, SendType.正常发送);
                result3 = zLGCANHelper.SentData(通道, 0x761, "22 FF FF FF FF FF FF FF", true, SendType.正常发送);
                result4 = zLGCANHelper.SentData(通道, 0x761, "23 FF FF F1 00 00 00 00", true, SendType.正常发送);

                if (!result1 || !result2 || !result3 || !result4)
                {
                    信息 = "发送数据失败,写车辆功能信息失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E F1 A8"))
                        {
                            信息 = "写车辆功能信息成功";
                            return true;
                        }
                    }
                }

                信息 = "写车辆功能信息失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 写ECU配置文件编号F1A9(int 通道, out string 响应, out string 信息)
        {
            信息 = "";
            响应 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                /*
                    10 08 2E F1 A9 31 33 33
                    21 33 34 00 00 00 00 00
                 */
                bool result1, result2;
                result1 = zLGCANHelper.SentData(通道, 0x761, "10 08 2E F1 A9 31 33 33", true, SendType.正常发送);
                result2 = zLGCANHelper.SentData(通道, 0x761, "21 33 34 00 00 00 00 00", true, SendType.正常发送);

                if (!result1 || !result2)
                {
                    信息 = "发送数据失败,写ECU配置文件编号失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E F1 A9"))
                        {
                            信息 = "写ECU配置文件编号成功";
                            return true;
                        }
                    }
                }

                信息 = "写ECU配置文件编号失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 写ECU装配日期数据4CE4(int 通道, out string 响应, out string 信息)
        {
            信息 = "";
            响应 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                /*
                    10 08 2E F1 A9 31 33 33
                    21 33 34 00 00 00 00 00
                 */
                bool result1, result2;
                result1 = zLGCANHelper.SentData(通道, 0x761, "10 0B 2E 4C E4 33 33 33", true, SendType.正常发送);
                result2 = zLGCANHelper.SentData(通道, 0x761, "21 33 33 33 33 34 00 00", true, SendType.正常发送);

                if (!result1 || !result2)
                {
                    信息 = "发送数据失败,写ECU装配日期数据失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E 4C E4"))
                        {
                            信息 = "写ECU装配日期数据成功";
                            return true;
                        }
                    }
                }

                信息 = "写ECU装配日期数据失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }

        [ExposedMethodAttribute("")]
        public bool 读ECU装配日期数据4CE4(int 通道, out string ECU装配日期数据Hex, out string ECU装配日期数据Asc, out int 字节长度, out string 信息)
        {
            ECU装配日期数据Hex = "";
            ECU装配日期数据Asc = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false, r2 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 4C E4 00 00 00 00", true, SendType.正常发送);
                    Thread.Sleep(50);
                    r2 = zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1 && r2)
                    {
                        break;
                    }
                }
                if (!r1 || !r2)
                {
                    信息 = "发送失败...";
                    ECU装配日期数据Hex = 信息;
                    ECU装配日期数据Asc = 信息;
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);

                string[] hexValues = new string[8];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                /*
                    10 0B 62 4C E4 FF FF FF
                    21 FF FF FF FF FF AA AA
                */
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("10"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 5 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                    if (s.Trim().StartsWith("21"))
                    {
                        ok21 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 1 || i > 5) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                字节长度 = hexValues.Length;
                var hexValues0 = "";
                if (!ok10 || !ok21)
                {
                    信息 = string.Join("", datas);
                    ECU装配日期数据Hex = 信息;
                    ECU装配日期数据Asc = 信息;
                    return false;
                }
                foreach (String hex in hexValues)
                {
                    int value = Convert.ToInt32(hex, 16);
                    string stringValue = Char.ConvertFromUtf32(value);
                    hexValues0 += stringValue;
                }
                信息 = string.Join(",", datas);
                ECU装配日期数据Hex = string.Join("", hexValues);
                ECU装配日期数据Asc = hexValues0;
                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }

        private static bool IsValidYYMMDD(string timeString)
        {
            if (string.IsNullOrEmpty(timeString) || timeString.Length != 6)
            {
                return false;
            }

            DateTime dateValue;
            string pattern = "yyMMdd";
            return DateTime.TryParseExact(timeString, pattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue);
        }
    }
}
